package controllers

import (
	"crypto/sha1"
	"encoding/json"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/satori/go.uuid"
	"io/ioutil"
)

type AuthorityController struct {
	beego.Controller
}
type Auth struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Team 	 string `json:"team"`
}
func (c *AuthorityController) Post() {
	bytes, err := ioutil.ReadAll(c.Ctx.Request.Body)
	if err != nil {
		panic(err)
	}
	var a *Auth
	err = json.Unmarshal(bytes, &a)
	if err != nil {
		fmt.Println(err)
	}
	salt, res := addSalt(a.Password)
	fmt.Println(salt)
	fmt.Println(res)

}

func addSalt(s string) (salt string, result []byte) {
	var err error
	u := uuid.Must(uuid.NewV4(), err)
	uuidstr := u.String()
	//sa := md5.Sum([]byte(uuidstr))
	salt = uuidstr
	sha1in := uuidstr + s
	res := sha1.Sum([]byte(sha1in))
	result = res[:]
	//fmt.Println(string(res[:]))
	return salt, result
}
